<?php
if ($this->count == 0) {
    echo "<table width='100%' border='0' cellspacing='5' cellpadding='2'>";
}
if ($this->count % 3 == 0) {
    echo "<tr>";
}

$imagePath = Yii::app()->request->baseUrl.$data->ref_image_path;

?>
<td align="center" valign="middle">
    <table width="200" border="0" cellspacing="5" cellpadding="0">
        <tr>
            <td>
                <a href="<? echo Yii::app()->request->baseUrl . '/index.php/ref/' . $data->ref_id; ?>">
                    <img src="<? echo $imagePath; ?>" width="200" height="126" border="0" />
                </a>
            </td>
        </tr>
        <tr>
            <td><?php echo CHtml::link($data->ref_name, array('ref/view', 'id' => $data->ref_id)); ?></td>
        </tr>
    </table>
</td>
<?php
if ($this->count % 3 == 2) {
    echo "</tr>";
}
if ($this->count == $this->modelLength - 1) {
    echo "</table>";
}
$this->count = $this->count + 1;
?>